<template>
  <div>
<van-nav-bar
  title="设置昵称"
  left-text="取消"
  right-text="完成"
  @click-left="onCancel"
  @click-right="onConfirm"
/>
<div class="box">
  <van-field
    v-model.trim="message"
    rows="3"
    maxlength="7"
    show-word-limit
    autosize
    type="textarea"
    placeholder="请输入昵称"
  />

</div>
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {
  name: 'UpdateName',
  props: {
    value: String
  },
  data () {
    return {
      message: this.value
    }
  },
  components: {},
  created () {},
  mounted () {},
  methods: {
    onCancel () {
      // 重置数据方式1-单个重置
      // this.message = this.value
      this.$emit('close')
    },
    async onConfirm () {
      // 通过debugger打断点
      // debugger
      // 非空判断
      if (this.message.length === 0) return
      // 发请求
      await updateUserProfile({ name: this.message })
      // 提示成功
      this.$toast.success('修改成功')
      // 修改数据
      this.$emit('input', this.message)
      // 关闭弹层
      this.$emit('close')
    }
  }
}
</script>

<style lang="less" scoped>
.box{
  padding: 20px;
}
</style>
